package com.yuanfengPlus.basicInfoManage.supplierInfo.service.impl;


import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.yuanfengPlus.basicInfoManage.supplierInfo.dao.ISupplierinfoDao;
import com.yuanfengPlus.basicInfoManage.supplierInfo.model.Supplierinfo;
import com.yuanfengPlus.basicInfoManage.supplierInfo.model.SupplierinfoDTO;
import com.yuanfengPlus.basicInfoManage.supplierInfo.service.ISupplierinfoservice;
import com.yuanfengPlus.basicInfoManage.warehouseinfo.model.Warehouseinfo;
import com.yuanfengPlus.utils.PageResult;
import com.yuanfengPlus.utils.Result;
import com.yuanfengPlus.utils.SnowflakeIdWorker;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service
public class SupplierinfoImpl implements ISupplierinfoservice {
    @Autowired
    ISupplierinfoDao isld;
    @Override
    public PageResult selectSupplierAll(SupplierinfoDTO supplierinfoDTO) {
        PageHelper.startPage(supplierinfoDTO.getPage(),supplierinfoDTO.getPageSize());
        Page<Supplierinfo> supplierinfos = isld.selectSupplierAll(supplierinfoDTO);
        return new PageResult(supplierinfos.getTotal(), supplierinfos.getResult());
    }

    @Override
    public Result<String> addSupplier(Supplierinfo supplierinfo) {
        SnowflakeIdWorker idWorker = new SnowflakeIdWorker(0);
        supplierinfo.setSupplier_id(idWorker.nextId());
        supplierinfo.setSupplier_time(new java.sql.Date(System.currentTimeMillis()));
        supplierinfo.setSupplier_amendtime(new java.sql.Date(System.currentTimeMillis()));
        Integer integer = isld.addSupplier(supplierinfo);
        if (integer > 0)
            return Result.success("添加成功");
        return Result.failure(400,"添加失败");
    }

    @Override
    public Result<String> updateSupplier(Supplierinfo supplierinfo) {
        Integer integer = isld.updateSupplier(supplierinfo);
        if (integer > 0)
            return Result.success("修改成功");
        return Result.failure(400,"修改失败");
    }

    @Override
    public Result<Supplierinfo> selectSupplier(String id) {
        Supplierinfo supplierinfo = isld.selectSupplier(id);
        if (supplierinfo != null)
            return Result.success(supplierinfo);
        return Result.failure(400,"没找到");
    }
}
